----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 800 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Immolate"
SPELL.m_sToolTip =	[[Burns the target for
					  20 damage over 10 seconds.]]
SPELL.m_sIcon = "devin/blackbetty/spells/mage/immolate.png"
SPELL.m_iCoolDown = 6.5
SPELL.m_iManaCost = 50
SPELL.m_bRequiresTarget = true
SPELL.m_iSpellType = SPELLTYPE_MAGICDAMAGE
---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )

	timer.Simple(0.1, function()
		pl:SetNWBool("Casting", false) 
		pl:SetNWBool("Casted", false)
	end)
	
	local range = self.m_iRange
	
	print("Casted "..self.m_sName.."!")
		
	if(target && target:IsValid() && target != pl) then
		pl:SetNWString("HoldType", "melee")
		pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_MELEE)
		pl:EmitSound("devin/blackbetty/weapons/castsounds/FireCast.wav", 100, 100+math.random(-10,10))
		ParticleEffectAttach( "fire_hands_instacast", PATTACH_POINT_FOLLOW, pl, pl:LookupAttachment("anim_attachment_RH"))
			
			timer.Simple(0.15, function()
				if(pl:GetPos():Distance(target:GetPos()) < range)then
					pl:EmitSound("devin/blackbetty/weapons/hit/Immolate.wav", 100, 100+math.random(-10,10))
					target:SetColor(Color(155, 85, 25, 255))
					ParticleEffect( "impact_firebig", target:GetPos() + Vector(0, 0, 64) + (target:GetAngles():Forward()*24), Angle(0,0,0), pl )
					if(timer.Exists("immolate_on_"..target:EntIndex()..""))then
						timer.Destroy("immolate_on_"..target:EntIndex().."")
					end
					timer.Create("immolate_on_"..target:EntIndex().."", 1, 10, function() 
						if(target:Health() <= 0) then 
							timer.Destroy("immolate_on_"..target:EntIndex().."")  
							target:SetColor(Color(255, 255, 255, 255))
						else
							local dmginfo_im = DamageInfo()
								dmginfo_im:SetDamage( 2 ) 
								dmginfo_im:SetDamageType( DMG_BURN )
								dmginfo_im:SetAttacker( pl ) 
								dmginfo_im:SetDamageForce( Vector( 0, 0, 1000 ) ) 
							local damageRadius = ents.FindInSphere(target:GetPos(), 240)
							target:TakeDamageInfo( dmginfo_im )
							for i, s in pairs(damageRadius)do
								if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm" and s:EntIndex() != target:EntIndex())then
									s:TakeDamageInfo( dmginfo_im )
								end
							end
							ParticleEffect( "impact_firesmall", target:GetPos() + Vector(0, 0, 32), Angle(0,0,0), pl )
							pl:EmitSound("devin/blackbetty/weapons/hit/Immolate.wav", 35, 100+math.random(10,30))
						end
					end)
					timer.Simple(10, function() if(IsValid(target))then target:SetColor(Color(255, 255, 255, 255)) end end)
			
				end
			end)
		timer.Simple(0.75, function()
			pl:SetNWString("HoldType", "melee2")
		end)
	end
end




